<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>回复</title>
<link rel="stylesheet" href="../../../js/layui/css/layui.css"
	media="all">

<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-family: '楷体'
}

.container {
	margin-top: 50px;
}

.zth-text {
	margin-bottom: 10px;
	font-size: 18px;
	margin-left: 30px;
}

.zth-but {
	margin-left: 170px;
	margin-top: 120px;
}
</style>
</head>
<body>
	<div id="app">
		<div>
			<div class="container">
				<div class="zth-text">请输入您要回复的内容:</div>
				<div class="layui-form-item layui-form-text">

					<div class="layui-input-block">
						<textarea placeholder="请输入内容" v-model="reply_body"
							class="layui-textarea" style="width: 300px;"></textarea>
					</div>
				</div>

				<div class="layui-form-item zth-but">
					<button class="layui-btn" @click="add">提交</button>
					<button type="button" id="close"
						class="layui-btn layui-btn-primary">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript" src="../../../js/layui/layui.js"></script>
	<script type="text/javascript" src="../../../js/vue/vue.js"></script>
	<script type="text/javascript" src="../../../js/vue/axios.min.js"></script>
	<script type="text/javascript">
	//截取要评论的id
		var href = location.href;
		var index = href.indexOf("=");
		var id = href.substr(index + 1, href.length);

		//成功方法
		function succeed() {
			layui.use([ 'form', 'jquery' ], function() {
				layer.alert("评论成功！", function() {
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
					parent.layer.close(index);
					//关闭父级页面的表格
					parent.layui.table.reload('testReload');
				});
			});
		}
		//关闭方法
		layui.use([ 'form', 'jquery' ], function() {
			var $ = layui.jquery
			$("#close").on('click', function() {
				layui.use([ 'form', 'jquery' ], function() {
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
					parent.layer.close(index);
					//关闭父级页面的表格
					parent.layui.table.reload('testReload');
				});
			});

		});

		new Vue({
			el : '#app',
			data : {
				//回复内容
				reply_body : '',
				//评论id
				comment_id : id
			},
			methods : {
				//修改评论操作
				add : function() {
					if (this.reply_body != null && this.reply_body != ''&&this.reply_body.indexOf(" ")==-1) {
						axios.get(
								'/ssb/comment/reply?reply_body='
										+ this.reply_body + '&comment_id='
										+ this.comment_id).then(function(res) {
							if (res.data > 0) {
								succeed();
							} else {
								alert("滚蛋！");
							}
						}, function(err) {
							console.log(err);
						});
					}else{
						alert("必填项不能为空（包括空格）");
					}
				}
			}
		});
	</script>
</body>
</html>
